const readline = require('readline-sync');


// for (let i = 1; i <= 3; i++) {
//     console.log('i', i);
//     for (let j = 1; j <= 5; j++) {
//         console.log('j', j);
//     }
// }

//打印2-100的所有质数

// for (let number = 2; number <= 100; number++) {
//     let text = true;
//     for (let i = 2; i < number; i++) {
//         if (number % i == 0) {
//             text = false;
//             break;
//         }
//     }
//     if (text) {
//         console.log(number);
//     }
// }

// 乘法表
// let sum = 0;
// let str = '';
// for (let i = 1; i <= 9; i++) {
//     for (let j = 1; j <= i; j++) {
//         sum = i * j;
//         str += i + '*' + j +'='+ sum+'  ';

//     }
//     console.log(str);
//     str ='';
// }
// console.log(str);



//求和
// let arr = [1, 52, 64, 52, 75, 64, 50];
// let sum = 0;
// 第一种
// for (let i = 0; i < arr.length; i++) {
//     sum += arr[i]
// }
// console.log(sum);
// 第二种
// for (let item of arr) {
//     sum += item;
// }
// console.log(sum);
// 第三种  (遍历对象)
// for (let index in arr) {
//     sum += arr[index];
// }
// console.log(sum);
// 第四种
// arr.forEach(function (item, index) {
//     sum += item;
//     // console.log(index);

// });
// console.log(sum);


// 登录  

// 登录  
let users = [
    ['zhangsan', 123, 500],
    ['lisi', 456, 1000]
];
let logintext = false;
let login = false;
let logindenglu = true;
let user;
let repeat = true;
let more = false;


while (logindenglu) {
    console.log('请输入账号');
    let id = readline.question();
    console.log('请输入密码');
    let password = readline.question();
    for (let item of users) {
        if (id == item[0] && password == item[1]) {
            logintext = true;
            user = item;
        }
    }
    if (logintext) {
        console.log(`欢迎你${id}`);
        login = true;
        logindenglu = false;
    } else {
        console.log(`查无此人`);
        more = true;
        if (more) {
            for (let i = 3; i > 0; i--) {
                console.log(`还有${i}次机会`);
                console.log('请输入账号');
                let id = readline.question();
                console.log('请输入密码');
                let password = readline.question();
                for (let item of users) {
                    if (i > 0 && id == item[0] && password == item[1]) {
                        logindenglu = true;
                    } else {
                        more = true;
                    }

                    if (logindenglu) {
                        console.log(`欢迎你${id}`);
                        login = true;
                        logindenglu = false;
                        break;
                    }
                }

            }

        }
    }

    if (login) {
        while (repeat) {
            console.log('1.存 2.取 3.查 4.退');
            let number = readline.question() - 0;
            switch (number) {
                case 1:
                    console.log('存钱');
                    let m = readline.question() - 0;
                    user[2] += m;
                    console.log(`本次存钱${m},余额为${user[2]}`);
                    console.log('返回上级,请按“1”');
                    let oo = readline.question();
                    break;
                case 2:
                    console.log('请输入取款余额');
                    let Withdrawal = Number(readline.question());
                    if (Withdrawal > user[2]) {
                        console.log('余额不足');
                    } else(console.log(`${user[2] -= Withdrawal}`));
                    console.log('返回上级,请按“1”');
                    let ll = readline.question();
                    // login: true;
                    break;
                case 3:
                    console.log(user[2]);
                    console.log('返回上级,请按“1”');
                    let uu = readline.question();
                    // login: true;
                    break;
                    case 4:
                        console.log('请输入转款余额');
                        let Transfer = Number(readline.question());
                        if (Transfer > user[2]) {
                            console.log('余额不足');
                        } else(console.log(`${user[2] -= Transfer}`));
                        console.log('返回上级,请按“1”');
                        let tt = readline.question();
                        // login: true;
                        break;
                case 5:
                    console.log('再见');
                    repeat = false;
                    break;
            }
        }
    }
}